package com.props.starter.demo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * Demo Controller for testing configuration management
 * 
 * @author Props Management Team
 */
@RestController
@RequestMapping("/demo1")
public class DemoController {

    @Value("${demo.app.name:Props Management Demo}")
    private String appName;

    @Value("${demo.app.version:1.0.0}")
    private String appVersion;

    @Value("${demo.app.author:Props Team}")
    private String appAuthor;

    @Value("${demo.database.url:jdbc:mysql://localhost:3306/demo_db}")
    private String databaseUrl;

    @Value("${demo.database.username:root}")
    private String databaseUsername;

    @Value("${demo.database.pool.max-size:10}")
    private int poolMaxSize;

    @Value("${demo.database.pool.timeout:30}")
    private int poolTimeout;

    @Value("${demo.cache.enabled:true}")
    private boolean cacheEnabled;

    @Value("${demo.cache.ttl:3600}")
    private int cacheTtl;

    @Value("${server.port:8080}")
    private int serverPort;

    /**
     * 获取当前配置信息
     */
    @GetMapping("/config")
    public Map<String, Object> getConfig() {
        Map<String, Object> config = new HashMap<>();
        
        // 应用配置
        Map<String, Object> app = new HashMap<>();
        app.put("name", appName);
        app.put("version", appVersion);
        app.put("author", appAuthor);
        config.put("app", app);
        
        // 数据库配置
        Map<String, Object> database = new HashMap<>();
        database.put("url", databaseUrl);
        database.put("username", databaseUsername);
        
        Map<String, Object> pool = new HashMap<>();
        pool.put("maxSize", poolMaxSize);
        pool.put("timeout", poolTimeout);
        database.put("pool", pool);
        config.put("database", database);
        
        // 缓存配置
        Map<String, Object> cache = new HashMap<>();
        cache.put("enabled", cacheEnabled);
        cache.put("ttl", cacheTtl);
        config.put("cache", cache);
        
        // 服务器配置
        Map<String, Object> server = new HashMap<>();
        server.put("port", serverPort);
        config.put("server", server);
        
        // 元数据
        config.put("timestamp", LocalDateTime.now());
        config.put("message", "Configuration loaded successfully! 🎉");
        
        return config;
    }

    /**
     * 健康检查
     */
    @GetMapping("/health")
    public Map<String, Object> health() {
        Map<String, Object> health = new HashMap<>();
        health.put("status", "UP");
        health.put("timestamp", LocalDateTime.now());
        health.put("app", appName);
        health.put("version", appVersion);
        return health;
    }

    /**
     * 应用信息
     */
    @GetMapping("/info")
    public Map<String, Object> info() {
        Map<String, Object> info = new HashMap<>();
        info.put("name", "Props Management Demo");
        info.put("description", "Demo application showcasing Props Management functionality");
        info.put("version", appVersion);
        info.put("author", appAuthor);
        info.put("timestamp", LocalDateTime.now());
        info.put("features", new String[]{
            "Configuration Management",
            "Version Control",
            "Real-time Updates",
            "Web Interface",
            "File Exclusion",
            "Cache Management"
        });
        return info;
    }
} 